Okay, so in today's lesson we are going to start looking at changing properties of parts.
Okay.
Now this will be split into two lessons because there's quite a lot to talk about.
And but you'd be lucky to have um, this lesson is a bit more a bit more easy than the second lesson.
So can introduce you to this first.
And then next lesson we can look at some of the more complex, not complex, but some of the more tricky
ones to change.
Okay, so to change a property we already know how to tell the script what object we're wanting to change.
Okay, now we need to tell it the property and what data or what to give the property.
What to change the property to be.
Okay, now if follows a general form.
Okay.
You first, um, reference the object which we already know how to do.
Then we write a dot and say the property name.
Okay, that's what comes next.
You then make that equal to a data type.
So a type of data okay.
And I'm just going to note this by using two dashes which notes that.
So anything that's noted in your in your script won't be read.
It won't be read by the script.
It's just for you to read.
Okay.
Um, so that's the general form for this.
Okay.
And we're going to have a look at the main thing to have a look at is the data types, as there's quite
a few different types of data that you'll need to know how to, how to use basically.
So let's click on the parts and let's have a look for its properties here.
Okay.
Um let's start off with transparency okay.
That's quite an easy one to change using the script, just as it's just a number, but it accepts okay.
So firstly we need to reference the object which is the part.
So from last lesson um remember there's two ways to reference it.
We're going to use the game dot method.
First there's going be a lot of referencing today as well.
So hopefully that will make you a bit more comfortable with that as well.
But we will need to be referencing every property, every lesson um, in in this scripting section as
well.
So you will, you will catch on to it eventually.
Um, so we are going to say um, game dot workspace, we're going from the works to the game, imaginary
game to the workspace, then to the part.
Okay.
That's our that's how you reference the object.
Then we want to say the property name.
So a property is treated as a child or treated as a member of the object.
So we can just write dot and just write it as you would do for another object.
Transparency.
Okay.
And we can see here this is quite important.
It says a says something here says number.
Here it will say different things.
Depending on what property you're changing and they're quite important.
Okay.
So we've now referenced the object and set the property name that we're wanting to change.
The only thing to do next then is to put in the data type okay.
Transparency just accepts a number from 0 to 1.
So it's as simple as just writing in the number you want to change it to.
So let's say 0.5 you write 0.5 and that's it.
We've now changed it to zero point.
Obviously it won't work until we run the game, which we can try out just in a minute.
Um, now you notice that I've written spaces before and after the equal sign.
Okay.
Um, if I, if I wrote it like this, it would still work completely fine.
Okay.
No issues with that either way.
I just, I just think it's much easier to read with those spaces in.
Okay.
This section of the course isn't just to teach you the basics, but also to teach you how to write code
in a readable and efficient way.
Okay.
And little things like this, if you get in the habit of will make reading the code for both you and
other people much easier.
Okay, so it's a good idea to put spaces in between there.
Again, if you don't want to.
It won't be wrong, but I would just highly recommend it.
Okay, so let's run the game and see what happens when we change that property.
We can see when we run the game soon as everything loads fine.
Immediately it changes to transparency of 0.5.
You can see we didn't change that.
It did it itself okay.
Which is how scripting is so cool.
So let's go back to the script.
And this here I'm going to write this note again is a number data type.
This is a type of data.
Okay.
Very similar to integer.
You might also see as well the difference between numbers and integers is that numbers can contain decimal
points.
So they can be 0.5 0.2.
Integers have to be whole numbers.
So 157 okay.
Can't have any decimal points.
Can't have any any dots in the number.
Okay.
Let's have a look at the second data type.
We're going to have a look at today.
Let's select the parts.
And let's look at anchored.
Okay.
Anchored has a tick box okay.
So let's reference anchored.
So let's say game dot workspace dot part dot anchored.
And we can see here this is a boolean data type okay.
Let's make it equal to.
And let's talk about data type.
So what Boolean means is it can either be one of two values.
So our anchored property here can either have a tick or no tick okay.
Which basically means it's on or off okay.
Anchor is either on or anchor is either off.
Another word of saying that is true and false.
Okay, a statement or something you say can either be true or false.
It can't be either as only it can only be it only be correct or incorrect, true or false.
Okay, we use the terms true and false when we're writing for data types okay.
So if you want anchor to be on we would say true.
We would write word true like that there.
If you wanted it to be off so not ticked you would just write false like that there as well.
So booleans are when you write either true or false okay.
So this is a boolean like that there okay cool.
Let's drop a line.
Let's have a look at another data type.
Let's have a look at name.
Name is just some text that you write in here okay.
Let's reference it the other way.
Let's reference it from a script I'm getting a bit bored of writing game dot workspace let's say script.
So I'm going to go from the script hasn't got any children.
So we need to go to the workspace which is its parent.
So we'd say dot parent.
Now with the workspace we can go back down again and go to the part.
Okay.
Let's end reference the name property name name.
There is a string.
We talked about string strings um, a couple lessons ago.
Um so strings how you use strings is you just write the text normally, but you need to use speech marks
before and after.
The reason is because if you were to write a keyword in there, a word which is special to the script,
something like print, if it sees a word, it, it, it, it thinks you're trying to use a function
or something else.
Okay.
Um, using those speech marks means that no matter what you write in there, it will not think you're
trying to use a function or something else.
It knows it's just text and not treat it as anything else, basically.
Okay.
Um, whenever a property can take any value.
So name, you can name it anything.
Okay.
That means it's a string.
Okay.
Um, so let's just name it.
Um, I don't know.
Um, my first part, for example.
Okay.
Like that, I'm going to emit in camel case again because it's easier to use.
Okay.
So this here is a string free text.
Finally, let's have a look at the last datatype we're going to look at today.
Um which is we're going to look at the parent what datatype that is.
So this is an object.
This is a parent is assigned to another object.
Okay.
Um.
Oh we need to undo that.
Oh.
So add an apart thing.
I clicked off it, which basically basically meant um, it doesn't have a parent.
It needs to have a parent, otherwise it can't exist.
Okay.
Um, okay.
So let's reference the part again.
So let's say script dot parent.
Just to make it more difficult, let's add a model into the game and put the part inside of a model.
You would say script dot parent dot model dot part okay is equal to and sorry dot part dot dot parent
okay.
Now this one's not as easy because it tells.
Shows you what the parent is, not what datatype it accepts because it is a property like anything else
you can change.
Okay.
Parent is an instance or otherwise called an object data type.
And this is when the property accepts another object.
So to give it that other object we just need to reference it.
So let's say we want to set the parent to be the workspace.
We wanted to go back to being parented to the workspace.
All we need to do is just reference the workspace which you already know how to do.
It's just game dot workspace.
That's simple.
You just reference the objects that it should be equal to and that there is your object, or it's also
called your instance.
They data data type as well.
Okay.
Some of these terms you will hear a lot later on as well.
But some of them mean very similar things as well.
Okay.
So just some examples on the first four.
Um, the four first four data types that you could use.
Okay.
So just to recap, you use a number or an integer whenever it's a number.
Okay.
Booleans you use when something is can either be one of two values.
You use strings when it can have any value.
So free text.
And when you use objects or instances when it's another object.
Okay.
So these are for now even though we only touched on four properties today.
Um, this allows you to change lots of other properties as well.
You can now change anything that has a number.
So like reflectance not the ones with three numbers.
We'll look at next lesson.
Route priority.
We haven't loaded that one but you can change it and other stuff.
Okay so with scripting it's very important that you apply what you know.
Okay I can't teach you every single possibility because of course would be infinite amount of hours
long.
Okay.
Um, scripting is about what you know, and applying it to unfamiliar cases.
Okay, so I teach you what you need to know.
Then in an actual when you're actually coding, you need to remember that and figure out how you can
use what you already know in your case when you need it.
Okay.
So that's all about applying what you know.
Okay.
So have a try out at changing those properties.
Okay.
Um, oh, one more thing I should probably just touch on this might throw an error.
Yes.
So because we changed the name of this to be my first part, um, and we called it part early on.
We changed the name.
It doesn't like that.
Okay.
And we also changed, um, we put it into a model where here we referenced it as game dot workspace
dot part.
Okay.
So when you are doing this it's a good idea to keep the name and the parent the same.
Okay.
Um, a bit boring, I know.
Um, but we will have a look later on in the course how to deal with that.
But for now, it's just a funny area that you would need to be aware of.
Okay.
Just wanted to drop that off before we finished.
So have a try out of those.
And next lesson we're going to have a look at four extra data types a little bit more tricky, but if
you know these ones I'm sure you'll be comfortable with the other four as well.